<?php

namespace App\Models;


class ChatRoom extends Model
{
    use ModelTrait;

    protected $table = 'chat_room';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'id',
        'chat_room_name',
        'created_at',
        'updated_at',
    ];

    public function chat_room_member()
    {
        return $this->hasMany(ChatRoomMember::class,'chat_room_id','id');
    }

    public function chat_room_member_me()
    {
        return $this->hasMany(ChatRoomMember::class,'chat_room_id','id');
    }

    public function chat_room_member_opposite()
    {
        return $this->hasMany(ChatRoomMember::class,'chat_room_id','id');
    }

    public function chat_room_message()
    {
        return $this->hasMany(ChatRoomMessage::class,'chat_room_id','id');
    }

    public function chat_room_last_message()
    {
        return $this->hasOne(ChatRoomMessage::class,'chat_room_id','id')->orderByDesc('created_at');
    }
}
